import cv2 as cv
import sys
import os
from python_ai.common.xcommon import *
import matplotlib.pyplot as plt
import numpy as np
import time
import datetime


def my_show_img(img, title="no title", trans=None, **kwargs):
    global spn
    spn += 1
    plt.subplot(spr, spc, spn)
    if trans is not None:
        img = trans(img)
    plt.imshow(img, **kwargs)
    plt.axis('off')
    plt.title(title)


img_dir = '../../../../../large_data/pic'
img_name = 'opencv_logo.png'
# img_name = 'IMG_20200819_124310.jpg'
# img_name = 'HSV.jpg'
img_path1 = os.path.join(img_dir, img_name)

spr = 1
spc = 2
spn = 0
plt.figure(figsize=[12, 6])

sep('load')
img = cv.imread(img_path1, cv.IMREAD_COLOR)
print('original shape', img.shape)
my_show_img(img, 'original', lambda x: cv.cvtColor(x, cv.COLOR_BGR2RGB))

# kernel = np.ones([5, 5], np.float32) / 25.
kernel = np.full([5, 5], 1./25., dtype=np.float32)
# dst = cv.filter2D(img, -1, kernel)
dst = convolution(img, kernel)
dst = np.uint8(dst)

my_show_img(dst, 'convolution result impl', lambda x: cv.cvtColor(x, cv.COLOR_BGR2RGB))
